<template>
  <div class="search-form-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <slot></slot>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="text" :icon="showSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" size="mini" @click="toggleSearch" style="margin-left: 10px;">{{ showSearch ? '收起' : '展开' }}</el-button>
      </el-form-item>
    </el-form>
    
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px" v-show="!showSearch">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="text" :icon="showSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" size="mini" @click="toggleSearch" style="margin-left: 10px;">{{ showSearch ? '收起' : '展开' }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "SearchForm",
  props: {
    queryParams: {
      type: Object,
      required: true
    },
    showSearch: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleQuery() {
      this.$emit('query')
    },
    resetQuery() {
      this.$emit('reset')
    },
    toggleSearch() {
      this.$emit('toggle-search')
    }
  }
}
</script>

<style scoped>
.search-form-container {
  margin-bottom: 15px;
}
</style>